package com.ruoyi.bpm.controller.admin.oa;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.bpm.controller.admin.oa.vo.BpmOALeaveCreateReqVO;
import com.ruoyi.bpm.controller.admin.oa.vo.BpmOALeavePageReqVO;
import com.ruoyi.bpm.controller.admin.oa.vo.BpmOALeaveRespVO;
import com.ruoyi.bpm.domain.oa.BpmOaLeave;
import com.ruoyi.bpm.service.oa.BpmOALeaveService;
import com.ruoyi.bpm.utils.BeanUtils;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.security.utils.LoginHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * OA 请假申请 Controller，用于演示自己存储数据，接入工作流的例子
 *
 * @author jason
 * @author 芋道源码
 */
@Tag(name = "管理后台 - OA 请假申请")
@RestController
@RequestMapping("/bpm/oa/leave")
@Validated
public class BpmOALeaveController {

    @Resource
    private BpmOALeaveService leaveService;

    @PostMapping("/create")
    @SaCheckPermission("bpm:oa-leave:create")
    @Operation(summary = "创建请求申请")
    public R<Long> createLeave(@Valid @RequestBody BpmOALeaveCreateReqVO createReqVO) {
        return R.ok(leaveService.createLeave(LoginHelper.getUserId(), createReqVO));
    }

    @GetMapping("/get")
    @SaCheckPermission("bpm:oa-leave:query")
    @Operation(summary = "获得请假申请")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public R<BpmOALeaveRespVO> getLeave(@RequestParam("id") Long id) {
        BpmOaLeave leave = leaveService.getLeave(id);
        return R.ok(BeanUtils.toBean(leave, BpmOALeaveRespVO.class));
    }

    @GetMapping("/page")
    @SaCheckPermission("bpm:oa-leave:query")
    @Operation(summary = "获得请假申请分页")
    public R<TableDataInfo<BpmOALeaveRespVO>> getLeavePage(@Valid BpmOALeavePageReqVO pageVO) {
        TableDataInfo<BpmOaLeave> pageResult = leaveService.getLeavePage(LoginHelper.getUserId(), pageVO);
        return R.ok(BeanUtils.toBean(pageResult, BpmOALeaveRespVO.class));
    }

}
